<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList1" @findClicked="findData" @Launchform="Launchform6" />

    <el-card style="margin-top: 10px" shadow="always" :body-style="{ padding: '5px' }">
      <div style="display: flex">
        <div style="width: 50%">
          <h1>{{ $t(`Print.RemainingMaterialDetailsToBeAdded`) }}</h1>
          <Table
            :isLoading="isLoading7"
            @currentRow="currentRow1"
            class="table1"
            :tableHeader="tableHeader6"
            :tableData="DetailsOfRemainingBinToBeFilledMethodsTableDateList"
            :TableHeight="100"
            :outTableHeight="60"
            @confirmChange="confirmChange1"
          />
        </div>
        <div style="width: 60%; margin-left: 10px">
          <h1>{{ $t(`Print.RemainingMaterialWarehousingDetails`) }}</h1>
          <Table
            :isLoading="isLoading8"
            @currentRow="currentRow2"
            :tableHeader="tableHeader1"
            :tableData="QueryDetailsOfRemainingMaterialsInStorageMehtodsPmarsTableDateList"
            :TableHeight="100"
            :outTableHeight="60"
          />
        </div>
      </div>
      <PageModule :PageData="{ pageSizeShow: true }" />
    </el-card>

    <el-drawer v-model="drawer1" :direction="'ttb'" size="small" :with-header="false">
      <Find
        :OriginalFilter="{ static: true }"
        :searchImg="false"
        style="margin-top: 12px"
        :formList="formList6"
        @Launchform="Launchform"
        @findClicked="findData6"
      />
      <Table
        @currentRow1="currentRowList"
        style="margin-top: 15px; width: 60%"
        :tableHeader="tableHeader2"
        :tableData="GeneralMaterialsQueryMethodsTableDateList.dtos"
        :TableHeight="100"
        :outTableHeight="65"
      />
      <PageModule :PageData="{ total }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
    </el-drawer>

    <el-drawer v-model="drawer2" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :formList="formList5" @findClicked="findData1" @Launchform="Launchform7" />
      <div style="width: 80%">
        <Table
          @currentRow1="currentRowList1"
          @currentRow="clicktogetdata"
          :isLoading="isLoading"
          style="margin-top: 15px"
          :tableHeader="tableHeader"
          :tableData="InsertInstructionMaterialQueryMethdosTableDateList.dtos"
          :TableHeight="50"
          :outTableHeight="65"
        />
        <PageModule :PageData="{ total: totalList }" @pageSizeChange="handleSizeChangeList" @pageChange="handleCurrentChangeList" />
      </div>
      <h1>{{ $t(`Print.LaminationSub_materialDetails`) }}</h1>
      <Table
        @currentRow1="currentRowList5"
        :isLoading="isLoading1"
        style="margin-top: 15px; width: 80%"
        :tableHeader="tableHeader3"
        :tableData="FitSubMaterialConditionsMehtodsTableDateList"
        :TableHeight="30"
        :outTableHeight="65"
      />
    </el-drawer>

    <el-drawer v-model="drawer3" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :formList="formList2" @Launchform="Launchform1" @findClicked="findData2" />
      <div style="width: 80%">
        <Table
          @currentRow1="currentRowList2"
          @currentRow="clicktogetdata"
          :isLoading="isLoading3"
          style="margin-top: 15px"
          :tableHeader="tableHeader5"
          :tableData="InsertTypeMaterialQueryMethodsTableDateList.dtos"
          :TableHeight="50"
          :outTableHeight="65"
        />
        <PageModule
          :PageData="{ total: totalListMethods }"
          @pageSizeChange="handleSizeChangeListMethods"
          @pageChange="handleCurrentChangeListMethods"
        />
      </div>
      <h1>{{ $t(`Print.LaminationSub_materialDetails`) }}</h1>
      <Table
        @currentRow1="currentRowList5"
        :isLoading="isLoading1"
        style="margin-top: 15px; width: 80%"
        :tableHeader="tableHeader3"
        :tableData="FitSubMaterialConditionsMehtodsTableDateList"
        :TableHeight="30"
        :outTableHeight="65"
      />
    </el-drawer>

    <el-drawer v-model="drawer5" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :formList="formList3" @Launchform="Launchform5" @findClicked="findData5" />
      <div style="width: 60%">
        <Table
          @currentRow1="currentRowList3"
          :isLoading="isLoading5"
          style="margin-top: 15px"
          :tableHeader="tableHeader6"
          :tableData="MaterialStockClothMethodsTableDateList.dtos"
          :TableHeight="100"
          :outTableHeight="60"
        />
        <PageModule :PageData="{ total: totalMaterial }" @pageSizeChange="handleSizeChangeMaterial" @pageChange="handleCurrentChangeMaterial" />
      </div>
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'TransferLeftoverMaterialsIn'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import {
  GeneralMaterialsQuery,
  MaterialCategory,
  type GeneralMaterialsQueryInterface,
  type GeneralMaterialsQueryPamrs,
  materialsClassification
} from '@/api/WarehouseDepartment/FactoryStorage/OtherOutboundOperations'
import {
  TheDetailsOfRemainingMaterialsInStorageWereAdded,
  EnterThePendingAddition,
  DeleteTheCurrentRow,
  RemainingMaterialToBeRemoved,
  QueryDetailsOfRemainingMaterialsInStorage,
  DetailsOfRemainingBinToBeFilled,
  MaterialStockCloth,
  InsertTypeMaterialQuery,
  FitSubMaterialConditions,
  InsertInstructionMaterialQuery
} from '@/api/WarehouseDepartment/FactoryStorage/TransferLeftoverMaterialsIn'
import type {
  EnterThePendingAdditionParms,
  QueryDetailsOfRemainingMaterialsInStorageParms,
  QueryDetailsOfRemainingMaterialsInStorageInterface,
  MaterialStockClothInterface,
  MaterialStockClothParms,
  InsertTypeMaterialQueryParms,
  InsertTypeMaterialQueryInterface,
  FitSubMaterialConditionsInterface,
  InsertInstructionMaterialQueryParms,
  InsertInstructionMaterialQueryTableDateList
} from '@/api/WarehouseDepartment/FactoryStorage/TransferLeftoverMaterialsIn'
import { ReasonForDelivery } from '@/api/WarehouseDepartment/FactoryStorage/OtherOutboundOperations'
import { ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { ElMessageBox } from 'element-plus'
import LoginWork from '@/utils/LoginWork'
const isLoading7 = ref(true)
const isLoading8 = ref(true)
const formList1 = ref([
  {
    type: 'button',
    checkboxLabel: '插入通用材料'
  },
  {
    type: 'button',
    checkboxLabel: '插入指令材料'
  },
  {
    type: 'button',
    checkboxLabel: '插入型体材料'
  },
  {
    type: 'button',
    checkboxLabel: '材料库'
  },
  {
    type: 'dateSingle',
    dateLabel: '入库日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '入库原因 ',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '入剩料批处理'
  },

  {
    type: 'input',
    inputPlaceholder: '入库单号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '入库原因',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'date',
    dateLabel: '入库日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '删除待入剩料明细当前行'
  },
  {
    type: 'button',
    checkboxLabel: '删除剩料入库明细当前行'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList6 = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '材料大类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '材料子类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料名称',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList5 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '材料名称',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList2 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入颜色',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '材料名称',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList3 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入材料颜色',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const clearFormList6 = () => {
  formList3.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
  })
}

const findData5 = (row: any) => {
  if (row === '置空') {
    clearFormList6()
  }
}

// 双击贴合子材料入库
const currentRowList5 = (row: any) => {
  row.color = row.mtlColor
  row.lotNo = mtlNo1List.value
  EnterThePendingAdditionParmsMethods.value.request.push(row)
  EnterThePendingAdditionMehtods()
}

// 待入剩料新增
const mtlNoTheDetailsOf = ref('')
const slipReasonTheDetailsOf = ref('')
const slipDateTheDetailsOf = ref('')

const TheDetailsOfRemainingMaterialsInStorageWereAddedMethods = async () => {
  const result = await TheDetailsOfRemainingMaterialsInStorageWereAdded(
    mtlNoTheDetailsOf.value,
    slipReasonTheDetailsOf.value,
    slipDateTheDetailsOf.value
  )
  if (result.code === 200) {
    DetailsOfRemainingBinToBeFilledMethods()
    QueryDetailsOfRemainingMaterialsInStorageMehtods()
    mtlNoTheDetailsOf.value = ''
    slipReasonTheDetailsOf.value = ''
    slipDateTheDetailsOf.value = ''
    formList1.value[5].selectValue = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const EnterThePendingAdditionParmsMethods = ref<EnterThePendingAdditionParms>({
  request: []
})

const type = ref(0)

const EnterThePendingAdditionMehtods = async () => {
  const reuslt = await EnterThePendingAddition(type.value, EnterThePendingAdditionParmsMethods.value.request as any)
  if (reuslt.code === 200) {
    EnterThePendingAdditionParmsMethods.value.request = []
    DetailsOfRemainingBinToBeFilledMethods()
    JMessage.success(reuslt.message)
  } else {
    EnterThePendingAdditionParmsMethods.value.request = []
    DetailsOfRemainingBinToBeFilledMethods()
    JMessage.error(reuslt.message)
  }
}

// 待入剩料明细修改
const confirmChange1 = async (row: any) => {
  row.remark === null ? (row.remark = '') : row.remark
  const result = await LoginWork.post<any, any>(`/pcFactorStockQuery/mTSTempUp?mtlNo=${row.mtlNo}&qty=${row.qty}&remark=${row.remark}`)
  if (result.code === 200) {
    DetailsOfRemainingBinToBeFilledMethods()
    JMessage.success(result.message)
  } else {
    DetailsOfRemainingBinToBeFilledMethods()
    JMessage.error(result.message)
  }
}

// 材料库 新增
const currentRowList3 = (row: any) => {
  row.color = row.mtlColor
  EnterThePendingAdditionParmsMethods.value.request.push(row)
  EnterThePendingAdditionMehtods()
}

// 插入型体材料 新增
const currentRowList2 = (row: any) => {
  row.color = row.styleColor
  row.style = row.styleNo
  EnterThePendingAdditionParmsMethods.value.request.push(row)
  EnterThePendingAdditionMehtods()
}

// 指令材料 新增
const currentRowList1 = (row: any) => {
  row.color = row.mtlColor
  EnterThePendingAdditionParmsMethods.value.request.push(row)
  EnterThePendingAdditionMehtods()
}

// 插入通用材料 新增
const currentRowList = (row: any) => {
  row.color = row.mtlColor
  EnterThePendingAdditionParmsMethods.value.request.push(row)
  EnterThePendingAdditionMehtods()
}

// 删除当前行记录
const currentRow2 = (row: any) => {
  console.log(row)
  const { mtlNo, slipNo } = row
  DeleteTheCurrentRowMehtodsSlipNp.value = slipNo
  DeleteTheCurrentRowMehtodsMtlNo.value = mtlNo
}

const DeleteTheCurrentRowMehtodsSlipNp = ref('')
const DeleteTheCurrentRowMehtodsMtlNo = ref('')

const DeleteTheCurrentRowMehtods = async () => {
  const result = await DeleteTheCurrentRow(DeleteTheCurrentRowMehtodsMtlNo.value, DeleteTheCurrentRowMehtodsSlipNp.value)
  if (result.code === 200) {
    QueryDetailsOfRemainingMaterialsInStorageMehtods()
    DeleteTheCurrentRowMehtodsSlipNp.value = ''
    DeleteTheCurrentRowMehtodsMtlNo.value = ''
    JMessage.success(result.message)
  } else {
    QueryDetailsOfRemainingMaterialsInStorageMehtods()
    DeleteTheCurrentRowMehtodsSlipNp.value = ''
    DeleteTheCurrentRowMehtodsMtlNo.value = ''
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc1 = (_done?: () => void) => {
  ElMessageBox.confirm('确定要删除该数据吗')
    .then(async () => {
      DeleteTheCurrentRowMehtods()
    })
    .catch(() => {})
}

// 待入剩料明细删除
const currentRow1 = (row: any) => {
  const { mtlNo, lotNo } = row
  RemainingMaterialToBeParms.value = mtlNo
  mtlNoTheDetailsOf.value = mtlNo
}

const RemainingMaterialToBeParms = ref('')

const RemainingMaterialToBeRemovedMethods = async () => {
  const result = await RemainingMaterialToBeRemoved(RemainingMaterialToBeParms.value)
  if (result.code === 200) {
    DetailsOfRemainingBinToBeFilledMethods()
    RemainingMaterialToBeParms.value = ''
    JMessage.success(result.message)
  } else {
    DetailsOfRemainingBinToBeFilledMethods()
    RemainingMaterialToBeParms.value = ''
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc = (_done?: () => void) => {
  ElMessageBox.confirm('确定要删除该数据吗')
    .then(async () => {
      RemainingMaterialToBeRemovedMethods()
    })
    .catch(() => {})
}

// 出库原因
const ReasonForDeliveryMehtods = async () => {
  const result = await ReasonForDelivery()
  formList1.value[5].selectOptions = EvaluatesTheArrayReturnValue(result)
  formList1.value[8].selectOptions = EvaluatesTheArrayReturnValue(result)
}

// 剩料入库明细
const QueryDetailsOfRemainingMaterialsInStorageMehtodsPmarsTableDateList = ref<QueryDetailsOfRemainingMaterialsInStorageInterface[]>([])

const Launchform6 = (row: any) => {
  QueryDetailsOfRemainingMaterialsInStorageMehtodsPmars.value.slipDateEnd = row[9].dateValue[1]
  QueryDetailsOfRemainingMaterialsInStorageMehtodsPmars.value.slipDateStart = row[9].dateValue[0]
  QueryDetailsOfRemainingMaterialsInStorageMehtodsPmars.value.slipNo = row[7].inputValue
  QueryDetailsOfRemainingMaterialsInStorageMehtodsPmars.value.slipReason = row[8].selectValue
  QueryDetailsOfRemainingMaterialsInStorageMehtods()
  slipReasonTheDetailsOf.value = row[5].selectValue

  slipDateTheDetailsOf.value = row[4].dateValue
}

const QueryDetailsOfRemainingMaterialsInStorageMehtodsPmars = ref<QueryDetailsOfRemainingMaterialsInStorageParms>({
  slipDateEnd: '',
  slipDateStart: '',
  slipNo: '',
  slipReason: '',
  type: ''
})

const QueryDetailsOfRemainingMaterialsInStorageMehtods = async () => {
  isLoading8.value = true
  const result = await QueryDetailsOfRemainingMaterialsInStorage(QueryDetailsOfRemainingMaterialsInStorageMehtodsPmars.value)
  QueryDetailsOfRemainingMaterialsInStorageMehtodsPmarsTableDateList.value = result
  isLoading8.value = false
}

// 待入剩料仓明细查询
const DetailsOfRemainingBinToBeFilledMethodsTableDateList = ref([])

const DetailsOfRemainingBinToBeFilledMethods = async () => {
  isLoading7.value = true
  const result = await DetailsOfRemainingBinToBeFilled()
  DetailsOfRemainingBinToBeFilledMethodsTableDateList.value = result.map((item: any) => {
    item.change = 'Y'
    return item
  })
  isLoading7.value = false
}

// 库存材料
const isLoading5 = ref(false)

const Launchform5 = (row: any) => {
  MaterialStockClothMethodsParms.value.mtlColor = row[0].inputValue
  MaterialStockClothMethods()
}

const drawer5 = ref(false)

const MaterialStockClothMethodsParms = ref<MaterialStockClothParms>({
  mtlColor: '',
  mtlName: '',
  mtlNo: '',
  mtlType: '',
  pageNum: 1,
  pageSize: 40,
  stkFlag: 0
})

const MaterialStockClothMethodsTableDateList = ref<MaterialStockClothInterface>({
  dtos: []
})

const MaterialStockClothMethods = async () => {
  isLoading5.value = true
  const result = await MaterialStockCloth(MaterialStockClothMethodsParms.value)
  MaterialStockClothMethodsTableDateList.value.dtos = result.dtos
  totalMaterial.value = result.total!
  isLoading5.value = false
}

const totalMaterial = ref(0)

const handleSizeChangeMaterial = (val: number) => {
  MaterialStockClothMethodsParms.value.pageSize = val
  MaterialStockClothMethods()
}

const handleCurrentChangeMaterial = (val: number) => {
  MaterialStockClothMethodsParms.value.pageNum = val
  MaterialStockClothMethods()
}

// 插入型体材料查询
const clearFormList3 = () => {
  formList2.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
  })
}

const findData2 = (row: any) => {
  if (row === '置空') {
    clearFormList3()
  }
}

const Launchform1 = (row: any) => {
  isLoading3.value = true
  InsertTypeMaterialQueryMethodsParms.value.styleNo = row[0].inputValue
  InsertTypeMaterialQueryMethodsParms.value.styleColor = row[1].inputValue
  InsertTypeMaterialQueryMethodsParms.value.mtlTypeNo = row[2].selectValue.split(' ')[0]
  InsertTypeMaterialQueryMethodsParms.value.mtlName = row[3].inputValue
  InsertTypeMaterialQueryMethods()
}

const isLoading3 = ref(true)

const InsertTypeMaterialQueryMethodsParms = ref<InsertTypeMaterialQueryParms>({
  mtlName: '',
  mtlTypeNo: '',
  pageNum: 1,
  pageSize: 40,
  styleColor: '',
  styleNo: ''
})

const InsertTypeMaterialQueryMethodsTableDateList = ref<InsertTypeMaterialQueryInterface>({
  dtos: []
})

const InsertTypeMaterialQueryMethods = async () => {
  const result = await InsertTypeMaterialQuery(InsertTypeMaterialQueryMethodsParms.value)
  InsertTypeMaterialQueryMethodsTableDateList.value.dtos = result.dtos
  if (result.dtos.length > 0) {
    mtlNo1List.value = result.dtos[0].mtlNo
    FitSubMaterialConditionsMehtods()
  }
  totalListMethods.value = result.total!
  isLoading3.value = false
}

const totalListMethods = ref(0)

const handleSizeChangeListMethods = (val: number) => {
  isLoading3.value = true
  InsertTypeMaterialQueryMethodsParms.value.pageSize = val
  InsertTypeMaterialQueryMethods()
}

const handleCurrentChangeListMethods = (val: number) => {
  isLoading3.value = true
  InsertTypeMaterialQueryMethodsParms.value.pageNum = val
  InsertTypeMaterialQueryMethods()
}

// 插入型体材料
const drawer3 = ref(false)

// 贴合子材料明细
const isLoading1 = ref(true)

const clicktogetdata = (row: any) => {
  const { mtlNo } = row
  mtlNo1List.value = mtlNo
  FitSubMaterialConditionsMehtods()
}

const FitSubMaterialConditionsMehtodsTableDateList = ref<FitSubMaterialConditionsInterface[]>([])

const mtlNo1List = ref('')

const FitSubMaterialConditionsMehtods = async () => {
  isLoading1.value = true
  const result = await FitSubMaterialConditions(mtlNo1List.value)
  FitSubMaterialConditionsMehtodsTableDateList.value = result.map((item: any) => {
    if (item.percent !== null) {
      item.percent = Number(item.percent).toFixed(0)
    }
    return item
  })
  isLoading1.value = false
}

// 插入指令材料查询
const clearFormList2 = () => {
  formList5.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
  })
}

const findData1 = (row: any) => {
  if (row === '置空') {
    clearFormList2()
  }
}

const Launchform7 = (row: any) => {
  isLoading.value = true
  InsertInstructionMaterialQueryMethdosPamrs.value.lotNo = row[0].inputValue
  InsertInstructionMaterialQueryMethdosPamrs.value.style = row[1].inputValue
  InsertInstructionMaterialQueryMethdosPamrs.value.typeNo = row[2].selectValue.split(' ')[0]
  InsertInstructionMaterialQueryMethdosPamrs.value.mtlName = row[3].inputValue
  InsertInstructionMaterialQueryMethdos()
}

const isLoading = ref(true)

const InsertInstructionMaterialQueryMethdosPamrs = ref<InsertInstructionMaterialQueryParms>({
  lotNo: '',
  mtlName: '',
  pageNum: 1,
  pageSize: 40,
  style: '',
  typeNo: ''
})

const InsertInstructionMaterialQueryMethdosTableDateList = ref<InsertInstructionMaterialQueryTableDateList>({
  dtos: []
})

const InsertInstructionMaterialQueryMethdos = async () => {
  const result = await InsertInstructionMaterialQuery(InsertInstructionMaterialQueryMethdosPamrs.value)
  InsertInstructionMaterialQueryMethdosTableDateList.value.dtos = result.dtos
  totalList.value = result.total!
  if (result.dtos.length > 0) {
    mtlNo1List.value = result.dtos[0].mtlNo
    FitSubMaterialConditionsMehtods()
  }
  isLoading.value = false
}

const totalList = ref(0)

const handleSizeChangeList = (val: number) => {
  isLoading.value = true
  InsertInstructionMaterialQueryMethdosPamrs.value.pageSize = val
  InsertInstructionMaterialQueryMethdos()
}

const handleCurrentChangeList = (val: number) => {
  isLoading.value = true
  InsertInstructionMaterialQueryMethdosPamrs.value.pageNum = val
  InsertInstructionMaterialQueryMethdos()
}

// 分类
const materialsClassificationMethods = async () => {
  let NewArray = []
  const result = await materialsClassification()
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.typeNo && item.typeName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.typeNo + ' ' + item.typeName)
    }
    return arr
  }, [])
  formList5.value[2].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
  formList2.value[2].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

// 插入指令材料
const drawer2 = ref(false)

// 通用材料

// 材料大类子类

const findData6 = (count: string) => {
  if (count === '置空') {
    clearFormList1()
  }
}

const clearFormList1 = () => {
  formList6.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
  })
}

const clearFormList5 = () => {
  formList1.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'date') {
      item.dateValue = ''
    }
  })
}

const findData = (count: any) => {
  if (count === '插入通用材料') {
    GeneralMaterialsQueryMethods()
    MaterialCategoryMethods()
    type.value = 1
    drawer1.value = true
  }
  if (count === '插入指令材料') {
    InsertInstructionMaterialQueryMethdos()
    type.value = 2
    drawer2.value = true
  }
  if (count === '插入型体材料') {
    InsertTypeMaterialQueryMethods()
    type.value = 3
    drawer3.value = true
  }
  if (count === '材料库') {
    MaterialStockClothMethods()
    MaterialStockClothMethods()
    type.value = 4
    drawer5.value = true
  }
  if (count === '删除待入剩料明细当前行') {
    if (RemainingMaterialToBeParms.value === '') {
      JMessage.warning('请选择需要删除的数据')
    } else {
      handleCloseMateriaLKlc()
    }
  }
  if (count === '删除剩料入库明细当前行') {
    if (DeleteTheCurrentRowMehtodsSlipNp.value === '' || DeleteTheCurrentRowMehtodsMtlNo.value === '') {
      JMessage.warning('请选择需要删除的数据')
    } else {
      handleCloseMateriaLKlc1()
    }
  }
  if (count === '入剩料批处理') {
    if (mtlNoTheDetailsOf.value === '' || slipReasonTheDetailsOf.value === '' || slipDateTheDetailsOf.value === '') {
      JMessage.warning('请选择需要入库的数据并且入库原因入库日期不可为空')
    } else {
      TheDetailsOfRemainingMaterialsInStorageWereAddedMethods()
    }
  }
  if (count === '置空') {
    clearFormList5()
  }
}

const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const MaterialCategoryMethodsQuery = ref('')

const MaterialCategoryMethods = async () => {
  let NewArray = []
  const result = await MaterialCategory(MaterialCategoryMethodsQuery.value)
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.typeNo && item.typeName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.typeNo + ' ' + item.typeName)
    }
    return arr
  }, [])
  formList6.value[0].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

const MaterialCategoryMethods1 = async () => {
  let NewArray = []
  const result = await MaterialCategory(MaterialCategoryMethodsQuery.value)
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.typeNo && item.typeName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.typeNo + ' ' + item.typeName)
    }
    return arr
  }, [])
  formList6.value[1].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

watch(MaterialCategoryMethodsQuery, () => {
  MaterialCategoryMethods1()
})

const Launchform = (row: any) => {
  MaterialCategoryMethodsQuery.value = row[0].selectValue.split(' ')[0]
  GeneralMaterialsQueryMethodsParms.value.mtlTypeL = row[0].selectValue.split(' ')[0]
  GeneralMaterialsQueryMethodsParms.value.mtlTypeS = row[1].selectValue.split(' ')[0]
  GeneralMaterialsQueryMethodsParms.value.mtlName = row[2].inputValue
  GeneralMaterialsQueryMethods()
}

const drawer1 = ref(false)

const GeneralMaterialsQueryMethodsParms = ref<GeneralMaterialsQueryPamrs>({
  mtlName: '',
  mtlTypeL: '',
  mtlTypeS: '',
  pageNum: 1,
  pageSize: 40
})

const GeneralMaterialsQueryMethodsTableDateList = ref<GeneralMaterialsQueryInterface>({
  dtos: []
})

const GeneralMaterialsQueryMethods = async () => {
  const result = await GeneralMaterialsQuery(GeneralMaterialsQueryMethodsParms.value)
  GeneralMaterialsQueryMethodsTableDateList.value.dtos = result.dtos
  total.value = result.total!
}

const total = ref(0)

const handleSizeChange = (val: number) => {
  GeneralMaterialsQueryMethodsParms.value.pageSize = val
  GeneralMaterialsQueryMethods()
}

const handleCurrentChange = (val: number) => {
  GeneralMaterialsQueryMethodsParms.value.pageNum = val
  GeneralMaterialsQueryMethods()
}

onMounted(() => {
  materialsClassificationMethods()

  DetailsOfRemainingBinToBeFilledMethods()

  QueryDetailsOfRemainingMaterialsInStorageMehtods()

  ReasonForDeliveryMehtods()
})

// 表格数据

const tableHeader = ref([
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    label: '序号',
    prop: 'seqNo'
  },
  {
    label: '部位',
    prop: 'partName'
  },
  {
    label: '段',
    prop: 'segment'
  },
  {
    label: '分类',
    prop: 'mtlTypeNo'
  },
  {
    label: '分类名称',
    prop: 'mtlType'
  },
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '用量',
    prop: 'ttlUsage'
  }
])

const tableHeader1 = ref([
  {
    label: '入库单号',
    prop: 'slipNo'
  },
  {
    label: '入库日期',
    prop: 'slipDate'
  },
  {
    label: '入库原因',
    prop: 'slipReason'
  },
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '备注',
    prop: 'remark'
  }
])

const tableHeader2 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料类型',
    prop: 'mtlTypeNo'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '颜色',
    prop: 'mtlColor'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '库存量',
    prop: 'stkQty'
  }
])

const tableHeader3 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '子材料名称',
    prop: 'mtlName'
  },
  {
    label: '子材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '比例',
    prop: 'percent'
  }
])

const tableHeader5 = ref([
  {
    label: '型体',
    prop: 'styleNo'
  },
  {
    label: '颜色',
    prop: '"styleColor'
  },
  {
    label: '序号',
    prop: 'seqNo'
  },
  {
    label: '部位',
    prop: 'partName'
  },
  {
    label: '段',
    prop: 'segment'
  },
  {
    label: '分类',
    prop: 'mtlTypeNo'
  },
  {
    label: '分类名称',
    prop: 'mtlType'
  },
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  }
])

const tableHeader6 = ref([
  {
    label: '指令',
    prop: 'lotNo',
    change: true
  },
  {
    label: '材料颜色',
    change: true,
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    change: true
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    change: true
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    change: true
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '备注',
    prop: 'remark'
  }
])
</script>

<style lang="less" scoped>
h1 {
  font-size: 16px;
}

.table1 {
  :deep(th:nth-child(6)) {
    color: red !important;
  }
}
</style>
